package com.hzhr.iot.device.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.controller.base.BaseController;
import com.hzhr.iot.device.model.bkMeter.*;
import com.hzhr.iot.device.service.BkMeterService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "BkMeter", description = "BK表")
@RestController
@RequestMapping(value = "")
public class BkMeterController extends BaseController {
    @Autowired
    BkMeterService bkMeterService;

    //region /bk-meters POST
    //region swagger响应码 : post
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : post
    @ApiOperation(value="实施档案-创建bk表台账", notes="实施档案-创建bk表台账  \n范围 : 无  \n步骤 :  \n1. 以系统用户身份：查询燃气用户，如果燃气用户不存在，抛出异常; (√)  \n2. 以系统用户身份：如果dtu物联台账不存在，则创建dtu的物联台账; (√)  \n3. 以系统用户身份：创建bk表采集台账，并关联刚才创建的dtu和燃气用户; (√)  \n",produces = "application/json")
    //endregion
    //region swagger参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/bk-meters", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<BkMeterPostResponseModel> post(@RequestParam @ApiIgnore Map<String, Object> query,
                                                         @RequestBody BkMeterPostModel body) throws ServiceException {
        BkMeterPostResponseModel responseBody = bkMeterService.post(initHeader(), query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
    //region /bk-meters DELETE
    //region swagger响应码 : delete
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : delete
    @ApiOperation(value="实施档案-删除bk表台账", notes="实施档案-删除bk表台账  \n范围 : 无  \n步骤 :  \n1. 以系统用户身份：删除该bk表的采集台账信息; (√)  \n",produces = "application/json")
    //endregion
    //region swagger参数 : delete
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : delete
    @RequestMapping(value = "/bk-meters", method = RequestMethod.DELETE)
    //endregion
    @Author
    public ResponseEntity<BkMeterDeleteResponseModel> delete(@RequestParam @ApiIgnore Map<String, Object> query,
                                                             @RequestBody BkMeterDeleteModel body) throws ServiceException {
        BkMeterDeleteResponseModel responseBody = bkMeterService.delete(initHeader(), query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
    //region /bk-meters PUT
    //region swagger响应码 : put
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : put
    @ApiOperation(value="实施档案-修改bk表台账", notes="实施档案-修改bk表台账  \n范围 : 无  \n步骤 :  \n1. 以系统用户身份：查询bk表信息，如果bk表不存在则报错; (√)  \n2. 以系统用户身份：修改bk表采集台账，如果修改了DTU号或用户号，须查询新的DTU或用户是否存在，如果不存在则报错，否则须关联新的DTU或用户号; (√)  \n",produces = "application/json")
    //endregion
    //region swagger参数 : put
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : put
    @RequestMapping(value = "/bk-meters", method = RequestMethod.PUT)
    //endregion
    @Author
    public ResponseEntity<BkMeterPutResponseModel> put(@RequestParam @ApiIgnore Map<String, Object> query,
                                                       @RequestBody BkMeterPutModel body) throws ServiceException {
        BkMeterPutResponseModel responseBody = bkMeterService.put(initHeader(), query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
}











































































































































































































































































































































































































































































































































































































































































